<template>
    <el-drawer
        v-model="isShow"
        size="50%"
        :destroy-on-close="true"
        @close="closeHandle"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        :show-close="false"
    >
        <template #header="{ titleId, titleClass }">
            <h4 :id="titleId" :class="titleClass">{{ title }}</h4>
        </template>
        <el-form :model="form" label-width="auto" label-position="right" ref="formRef" :rules="rules">
            <el-row :gutter="20">
                <el-col :span="24">
                    <el-form-item label="案件名称" required prop="name">
                        <el-input v-model="form.name" placeholder="请输入案件名称"
                        @click="SelectCaseListRef.showCaseList()"
                         :readonly="isreadonly"/>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="部门受案号">
                        <el-input v-model="form.casecode" placeholder="请输入部门受案号" :readonly="isreadonly"/>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="承办人">
                        <el-input v-model="form.casecode" :readonly="isreadonly"/>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="赃证物类别">
                        <el-row style="width:100%"  :gutter="20">
                            <el-col :span="10">
                                <el-input v-model="form.zhengwutype" :readonly="isreadonly"/>
                            </el-col>
                            <el-col :span="14">
                                <el-radio-group v-model="form.zhengwutype" :readonly="isreadonly">
                                    <el-radio value="文书卷" border>文书卷</el-radio>
                                    <el-radio value="证据卷" border>证据卷</el-radio>
                                    <el-radio value="补充侦查卷" border>补充侦查卷</el-radio>
                                </el-radio-group>
                            </el-col>
                        </el-row>
                    </el-form-item>
                </el-col>
                <!-- <el-col :span="24">
                    <el-form-item label="超高频RFID码">
                        <el-input v-model="form.casecode" clearable :readonly="isreadonly"/>
                    </el-form-item>
                </el-col> -->
                <el-col :span="24">
                    <el-form-item label="条码">
                        <el-input v-model="form.casecode" clearable :readonly="isreadonly"/>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="状态">
                        <el-select
                            v-model="form.status"
                            placeholder="请选择状态"
                            clearable
                        >
                            <el-option
                                v-for="dict in sys_normal_disable"
                                :key="dict.value"
                                :label="dict.label"
                                :value="dict.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <el-button type="primary" @click="submitHandleAndNew">同案号继续新增</el-button>
            <el-button type="primary" @click="submitHandle">提交</el-button>
            <el-button @click="isShow = false">关闭</el-button>
        </template>
    </el-drawer>
    <SelectCaseList ref="SelectCaseListRef" @getCaseDatas="getCaseData"></SelectCaseList>
</template>
<script setup>
const {proxy} = getCurrentInstance()
// import {getCaseInfoList,getCaseInfoInfo} from "@/api/CaseInfo/CaseInfo";
import SelectCaseList from "@/components/Case/SelectCaseList.vue";
import { watch } from "vue";

const {sys_normal_disable,} = proxy.useDict('sys_normal_disable',)
// 是否显示抽屉
const isShow = ref(false)
const SelectCaseListRef = ref()

const isreadonly = ref(true)
// 抽屉标题
const title = ref('')
const rules = {
    name: [{ required: true, message: "案件名称不能为空", trigger: "change" }],
    unitId: [{ required: true, message: "办案单位不能为空", trigger: "blur" }],
    depid: [{ required: true, message: "办案部门不能为空", trigger: "blur" }],
}

const isAdd = ref(true)

const form = ref({
    
})
// 通知事件
const emit = defineEmits(['getList'])


const changeShowStatus = () => {
    isShow.value = !isShow.value
}

onMounted(() => {
    
})

const showAddEditCase = () => {
    title.value = '新增案件';
    isAdd.value = true
    isreadonly.value = false
    changeShowStatus()
}

const showEditCase = async (data,OperateType) => {
    if(OperateType == "edit"){
        title.value = '修改案件信息'
        isAdd.value = false
        isreadonly.value = false
    }else{
        title.value = '案件信息详情'
        isAdd.value = false
        isreadonly.value = true
    }
    // 对传过来的案由中文进行查找出其对应的casebriefId值
    // await getCaseInfoInfo(data.caseCaseinfoId).then(res => {
    //         form.value = res.data
    //         getDepartment()
    //     })
    changeShowStatus()
}

defineExpose({showAddEditCase,showEditCase})


const submitHandle = async () => {
    proxy.$refs["formRef"].validate(valid => {
        if (valid) {
            if (form.value['caseCaseinfoId']) {
                editCaseInfo(form.value).then(res => {
                    changeShowStatus()
                    emit('getList', '来了老弟')
                })
            } else {
                createCaseInfo(form.value).then(res => {
                    changeShowStatus()
                    emit('getList', '来了老弟')
                })
            }
        }
    });
}

const submitHandleAndNew = async () => {
    proxy.$refs["formRef"].validate(valid => {
        if (valid) {
            proxy.$modal.msgSuccess("同案号新增");
            // ---执行新增接口--
            // createCaseInfo(form.value).then(res => {
            //         emit('getList', '来了老弟')
            //     })
            // form.value.赃证物类别 = ''
            // form.value.条码 = ''
            // form.value.状态 = ''
        }
    });
}
const getCaseData = (data) => {
    console.log("儿子传过来数据了",data)
    form.value.name = data.name
    form.value.casecode = data.casecode
}
// 关闭后的回调事件
const closeHandle = () => {
    form.value = {
        
    }
}
</script>

<style lang="scss" scoped>
h4{margin:0;}
:deep() .el-date-editor {
  width: 100%;
}
:deep() .el-cascader{width: 100%;}
:deep() .el-drawer__body{padding: 20px 0;}
:deep() .el-radio__input{display: none;}
</style>